/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jsibbold.zoomage.example.slice;

import com.jsibbold.zoomage.ZoomageView;
import com.jsibbold.zoomage.example.CustomSwitchPopup;
import com.jsibbold.zoomage.example.ResourceTable;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.enums.PopupAnimation;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Image;

/**
 * MainAbilitySlice
 *
 * @since 2021-05-27
 */
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private ZoomageView zoomageView;
    private Image settingImage;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initComponent();
        initData();
    }

    private void initComponent() {
        zoomageView = (ZoomageView) findComponentById(ResourceTable.Id_demoView);
        settingImage = (Image) findComponentById(ResourceTable.Id_settingImage);
        settingImage.setClickedListener(this::onClick);
    }

    private void initData() {
        zoomageView.setResPixelMap(ResourceTable.Media_zoom_demo);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_settingImage:
                new XPopup.Builder(getContext())
                    .popupAnimation(PopupAnimation.NoAnimation)
                    .asCustom(new CustomSwitchPopup(getContext(), this, zoomageView))
                    .show();
                break;
            default:
        }
    }
}
